<template>
  <div v-loading="loading" class="bg-white rounded-20px p-30px h-full">
    <div class="flex items-center justify-between">
      <div class="flex items-center gap-10px">
        <el-image class="w-13px h-23px" :src="require('@/assets/images/analysis/before.png')" fit="contain"></el-image>
        <div class="text-20px font-bold text-black">三方仓</div>
      </div>
      <div class="flex items-center gap-10px">
        <div class="flex items-center gap-5px" style="border-right: 1px solid #AAB0BB; padding-right: 10px;">
          <div
            v-for="(dateItem, dateiIndex) in dateList"
            :key="dateiIndex"
            class="tag"
            :class="currentTag === dateiIndex ? 'active' : ''"
            @click="currentTag = dateiIndex"
          >{{ dateItem }}
          </div>
        </div>
        <el-image class="w-15px h-14px" :src="require('@/assets/images/analysis/download.png')" fit="contain"></el-image>
      </div>
    </div>
    <div class="mt-20px">
      <div class="flex items-start flex-wrap gap-10px">
        <div
          v-for="(item, index) in cardList"
          :key="index"
          class="card"
        >
          <div class="flex items-center justify-between gap-14px p-10px">
            <div></div>
            <el-image class="w-15px h-14px" :src="require('@/assets/images/analysis/download.png')" fit="contain"></el-image>
          </div>
          <div class="line"></div>
          <el-scrollbar class="overflow-hidden" style="height: 140px;">
            <div class="p-10px text-center">
              <el-tooltip class="item" effect="dark" :content="item.name" placement="top">
                <div class="text-16px mb-5px" style="color: #2386FF; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;">
                {{ item.name }}
                </div>
              </el-tooltip>
              <div class="text-14px mb-5px" style="color: #616161;">
                在库：{{ item.entryCount }}
              </div>
              <div class="text-14px mb-5px" style="color: #616161;">
                入库：{{ item.inCount }}
              </div>
              <div class="text-14px mb-5px" style="color: #616161;">
                出库：{{ item.outCount }}
              </div>
              <div
                v-for="(citem, cindex) in item.data"
                :key="cindex"
                class="text-12px"
                style="color: #616161;"
              >
                <div v-if="citem.name">
                  {{ citem.name }}：{{ citem.value }}
                </div>
              </div>
            </div>
          </el-scrollbar>
        </div>

      </div>
    </div>
  </div>
</template>

<script>
import { warehouseTripartiteStatusApi } from '@/api/hs/bigscreen';

export default {
  name: "ThirdPartyData",
  data() {
    return {
      cardList: [],
      currentTag: 2,
      dateList: [
        '日',
        '周',
        '月'
      ],
      loading: false,
      interval: null,
    };
  },
  watch: {
    currentTag() {
      this.warehouseTripartiteStatus();
    }
  },
  created() {
    this.warehouseTripartiteStatus();
    this.interval = setInterval(() => {
      this.warehouseTripartiteStatus();
    }, 10000);
  },
  methods: {
    warehouseTripartiteStatus() {
      this.loading = true;
      return new Promise((resolve, reject) => {
        warehouseTripartiteStatusApi(this.currentTag + 1)
          .then(res => {
            this.cardList = this.filterInStockData(res.data);

            resolve(res.data);
          }).catch(err => {
            reject(err);
          }).finally(() => {
            this.loading = false;
          });
      });
    },
    filterInStockData(arr) {
      const result = arr.map(item => ({
        name: item.warehouseName,
        entryCount: item.entryCount,
        inCount: item.inCount,
        outCount: item.outCount,
        data: item.customerCountDataList.map(item => ({
          name: item.customerName,
          value: item.count
        }))
      }))
      return result;
    },
  },
  destroyed() {
    this.clearDataInterval();
  },
};
</script>

<style lang="scss" scoped>
.card {
  width: calc(100% / 10 - 9px);
  height: 190px;
  background: #FFFFFF;
  box-shadow: 2px 2px 5px 0px rgba(26,100,190,0.15), -2px -2px 5px 0px rgba(226,235,246,0.2);
  border-radius: 6px 6px 6px 6px;
}
.line {
  height: 2px;
  background: linear-gradient(to right, #E8EFF8, #F5F8FC);
}
.tag {
  padding: 5px 10px;
  color: #AAB0BB;
  font-size: 12px;
  border: 1px solid transparent;
  cursor: pointer;
  border-radius: 10px;
  &.active {
    color: #2386FF;
    border-color: #2386FF;
  }
}
</style>
